<?
include_once("db/ControleBanco.php");
include_once("db/Tabela.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title></title>
<style type="text/css">
<!--
body {
	background-color: #0033CC;
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
-->
</style>
<link href="css/default.css" rel="stylesheet" type="text/css" />

<script language="javascript" type="text/javascript">
function conectar(){
	var form = document.formBanco;
	form.action = "";
	form.target = "";
	form.submit();
}
function avancar(){
	var form = document.formBanco;
	form.action = "opcoes.php";
	form.target = "mainFrame";
	form.submit();
}
</script>
</head>
<body>
<table width="99%" height="99%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td valign="top"><p class="tituloBranco">Banco de Dados </p>
      <form name="formBanco" action="" target="" method="post">
        <table border="0" cellpadding="0" cellspacing="3" width="100%">
          <tr>
            <td class="rotuloBranco">Host:</td>
            <td><input type="text" name="host" value="<? echo $_POST['host']?>" style="width:99%" /></td>
          </tr>
          <tr>
            <td class="rotuloBranco"> Usu&aacute;rio: </td>
            <td><input type="text" name="usuario" value="<? echo $_POST['usuario']?>" style="width:99%" /></td>
          </tr>
          <tr>
            <td class="rotuloBranco">Senha:</td>
            <td><input type="password" name="senha" value="<? echo $_POST['senha']?>" style="width:99%" /></td>
          </tr>
          <tr>
            <td></td>
            <td><input name="submit" type="submit" value="Conectar" onclick="conectar();" /></td>
          </tr>
          <tr>
            <td></td>
            <td>&nbsp;</td>
          </tr>
          <?
		 	if($_POST['host'] != ""){
				$cBanco = new ControleBanco(new DadosBanco($_POST['host'], $_POST['banco'], $_POST['usuario'], $_POST['senha']));
				$cBanco->conectar();
		  ?>
          <tr>
            <td class="rotuloBranco">Banco:</td>
            <td><select name="banco" style="width:99%">
                <? 
					$bancos = $cBanco->listarBancos();
					for($i = 0; $i < count($bancos); $i++){
				?>
                <option value="<?  echo $bancos[$i]->getTitulo()?>" <? if($_POST['banco'] == $bancos[$i]->getTitulo()){?>selected="selected"<? } ?>>
                <?  echo $bancos[$i]->getTitulo()?>
                </option>
                <? 
					}
				?>
              </select></td>
          </tr>
          <tr>
            <td></td>
            <td><input name="submit2" type="submit" value="Conectar" onclick="conectar();" /></td>
          </tr>
          <?
		  	}
		  ?>
        </table>
		<?
			if($_POST['banco'] != ""){
		?>
        <br />
        <table border="0" cellpadding="0" cellspacing="3" width="100%">
		  <?
					$tabelas = $cBanco->listarTabelas();
					for($i = 0; $i < count($tabelas); $i++){
				?>
          <tr>
            <td width="30" align="center"><input name="tabelas[]" type="checkbox" id="tabelas[]" value="<? echo $tabelas[$i]->getTitulo()?>" /></td>
            <td class="rotuloBranco"><? echo $tabelas[$i]->getTitulo()?></td>
          </tr>
          <?
                	}
				?>
        </table>
		<table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td align="right"><input name="submit22" type="submit" onclick="avancar();" value="Avan&ccedil;ar &gt;&gt;   " /></td>
          </tr>
        </table>
		<?
			}
		?>
      </form>
      <p class="tituloBranco">&nbsp;</p></td>
  </tr>
</table>
</body>
</html>
